<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }



    body {
        width: 100%;
        height: 100%;
        background-color: orange;
    }

    .box {
        margin: 140px auto;
        width: 400px;
        /* height: 500px; */
        border-radius: 14px;
        background-color: white;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding:20px 30px;
    }

    .top {
        width: 360px;
        height: 88px;
        background-color: pink;
    }

    .boreder {
        margin-top: 25px;
        width: 360px;
        height: 83px;
        background-color: aqua;
        text-align: center;
    }

    h1 {
        font-size: 22px;
    }

    .input1 {
        width: 236px;
        height: 30px;
    }

    button {
        width: 70px;
        height: 35px;
    }
    li {
        list-style: none;
        display: flex;
        justify-content: space-between;
    }
    .left{
        width: 320px;
    }
    a{
        text-decoration: none;
    }
    .footer{
        margin-top: 20px;
        text-align: center;
    }
</style>

<body>
    <div id="app">
        <div class="box">
            <div class="box_conter">
                <div class="top"></div>
                <div class="boreder">
                    <h1>爱上对方过后就哭了》</h1>
                    <input class="input1" type="text" v-model="val">
                    <button @click="btn">submit</button>
                </div>
                <ul>
                    <li v-for="item,index in goods">
                        <div class="left">
                            <input type="checkbox" :checked="item.dowe" v-model="goods[index].down">
                            <span>{{ goods[index].val }}</span>
                        </div>
                        <div class="right">
                            <a href="#" @click="clean(index)">X</a>
                        </div>
                    </li>
                </ul>

                <div class="footer">
                    <p v-show="off">Congrat, you have no more tasks to do</p>
                    <p v-show="on">
                        <span>{{allSun}}个</span>
                        <span>全部</span>
                        <span @click="clean1(item)">清除</span>
                    </p>
                </div>
            </div>
        </div>
    </div>

    <script src="../vue/vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            created() {

            },
            data: {
                num: -1,
                val: "",
                goods: [],
                off:true,
                on:false,
                faly:false,
                
            },
            methods: {
                btn() {
                    if (this.val.length > 0) {
                        this.num += 1;
                        // this.goods.push(this.val);
                        this.goods.push({
                            val:this.val,
                            number:1,
                            down:false
                        });
                        this.val = "";
                        console.log(this.goods[0].down);
                    } else {
                        this.val = "";
                    }
                },
                clean(item){
                    console.log(this.goods.splice(item,1));
                },
                clean1(item){
                     return   this.goods.filter(function(item,index,arr){
                            if(item.down){
                                this.goods.splice(item,1)
                            }
                        })
                    console.log(123);
                }
            },
            watch: {
                goods(newValue, oldValue) {
                    if(this.goods.length >0){
                        this.off = false;
                        this.on = true;
                    };

                    
                },
            },
            computed:{
                allSun(){
                    return this.goods.reduce((prev,next) =>{
                        if(next.down){
                            return prev + next.number - 1
                        }else{
                            return prev + next.number

                        }
                    },0)
                }
            }

        })
    </script>
</body>

</html>